package ui.fragment.minefragment;

import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.just.agentweb.AgentWeb;
import com.just.agentweb.AgentWebView;

import java.util.HashMap;
import java.util.Map;

import base.BaseBean;
import base.fragment.BaseNetFragment;
import bean.ServiceAgreementBean;
import student.andlei.com.student.R;
import utils.GsonUtils;

/**
 * 关于我们
 */
public class AboutUsFragment extends BaseNetFragment{
    private AgentWeb mAgentWeb;
    private AgentWebView agentWebView;
    private TextView tv_info;
    public static Fragment getInstance() {
        return new AboutUsFragment();
    }
    @Override
    public void success(String action, BaseBean baseBean) {
        if(baseBean.code == 200){
            ServiceAgreementBean agreementBean = (ServiceAgreementBean) GsonUtils.getInstance(context).parseComplexJArrayByCommon(baseBean,ServiceAgreementBean.class);
            mAgentWeb = AgentWeb.with(AboutUsFragment.this)
                    .setAgentWebParent(agentWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
                    .useDefaultIndicator()
                    .createAgentWeb()
                    .ready()
                    .go(agreementBean.url);
        }else {
            toast(baseBean.msg);
        }
    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_aboutus;
    }

    @Override
    protected void findViews() {
        tv_info = getView(R.id.tv_aboutus_info);
        agentWebView = getView(R.id.AgentWebView);
    }

    @Override
    protected void formatViews() {

    }

    @Override
    protected void formatData() {
        tv_info.setText("公司简介\n\n" +
                "本公司成立于2017年4月，从成立至今一直致力于教育智能产品的研发、销售等业务领域。本公司始终秉承着“服务学生，服务学校，服务社会”的心态，着眼于教育改革需求，为广大师生和教育机构提供智能化服务。\n" +
                "公司宗旨\n\n" +
                "科技助力教育，知识改变命运\n\n" +
                "公司理念\n\n" +
                "专心，专注，专业\n\n" +
                "公司愿景\n\n" +
                "轻松教，精准学，共享优质教学资源");
        loadData();
    }
    private void loadData(){
        //1服务协议 2积分规则 3关于我们
        Map<String,Object> map = new HashMap<>();
        map.put("type",3);
        post("common/article",map,BaseBean.class,false);
    }
    @Override
    protected void getBundle() {

    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){
            loadData();
        }
    }
}
